package com.itheima.jdbcdemo;

import org.junit.jupiter.api.Test;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

public class JdbcDemo2 {
    @Test
    public void test(){
        //创建数据源
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        //绑定驱动地址
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUsername("root");
        dataSource.setPassword("");
        dataSource.setUrl("jdbc:mysql://192.168.203.128:3306/case2test");
        //创建templet模板对象
        JdbcTemplate template = new JdbcTemplate();
        template.setDataSource(dataSource);

        //书写sql语句
        String sql = "insert into account values (null,?,?)";

        //sql的参数与update方法中的参数一致
        int count = template.update(sql, "胡歌", 5000f);

        System.out.println(count);

    }
}
